<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

	<head>
		<title>ksqUrl</title>
		<link rel="icon" href="<?php include '../includes/install_path.php'; echo $install_path; ?>favicon.ico">
		<link rel=StyleSheet href="<?php include '../includes/install_path.php'; echo $install_path; ?>includes/style.css">
<meta name="description" content="ksqUrl: The open source URL shortener. By Techerrata. http://code.google.com/p/ksqurl/>
<meta http-equiv="content-language" content="en">
<meta name="author" content="Kevan Kay">
<meta name="robots" content="follow,index">
	</head>
<body>
		<br/><a href="<?php include '../includes/install_path.php'; echo $install_path; ?>"><img src="<?php include '../includes/install_path.php'; echo $install_path; ?>logo.png" border="0"><img src="<?php include '../includes/install_path.php'; echo $install_path; ?>spacer.png" border="0" width="298px" height="0px"></a>
	<br/>

<div class="tip-display" id="tip-display" style="display:block;" onclick="document.getElementById('tip-display').style.display=(document.getElementById('notification-display').style.display== 'block')?'none':'block';" style="cursor: pointer;">
<h3>Version 1.0.0</h3>
</div><?php
/* 
ksqUrl 1.0.0
Written by Kevan 2/4/2011
*/

// make it look pretty
echo "<br/><form>";
// assign varibles
$domain = $_POST['domain'];
$webname = $_POST['webname'];
$sql_username = $_POST['sql_username'];
$sql_password = $_POST['sql_password'];
$sql_database = $_POST['sql_database'];
$sql_host = $_POST['sql_host'];
$sql_table = $_POST['sql_table'];
$search_page = $_POST['search_page'];
$random_links = $_POST['random_links'];
$play_mp3 = $_POST['play_mp3'];
$play_flv = $_POST['play_flv'];
$play_img = $_POST['play_img'];
$preview = $_POST['preview'];
$appkey = $_POST['appkey'];
$configfile = "../includes/config.php";


// Fill database
echo "<h3>Filling database</h3>";

// Open Database
mysql_connect($sql_host, $sql_username, $sql_password) or die('<font color=#CC3300>Error: Could not connect to MySQL server!</font>');
		mysql_select_db($sql_database) or die('<font color=#CC3300>Error: Could not find database!</font><br />');

//Begin database functions

/* Accepts a filename and imports the SQL script in it.

   Returns: true if all is well
            false if something is wrong
            (error message is embedded in $errmsg)

   One can also use mysql_error() if this function
   returns an error.

*/

/* Installs a DB with a given name with the help of a given
   .sql file

   Returns: true if all is well
       false if something is wrong
            (error message is embedded in $errmsg)

   One can also use mysql_error() if this function
   returns an error.

*/

function mysql_install_db($dbname, $tablename, &$errmsg)
{
   $result = true;

   if(!mysql_select_db($dbname))
   {
     $result = mysql_query("CREATE DATABASE $dbname");
     if(!$result)
     {
        $errmsg = "<font color=#CC3300>Error: Could not create [$dbname] database in mysql.</font>";
        return false;
     }
     $result = mysql_select_db($dbname);
   }

   if(!$result)
   {
      $errmsg = "<font color=#CC3300>Error: Could not select [$dbname] database in mysql.</font>";
      return false;
   }
   $query="CREATE TABLE IF NOT EXISTS `$tablename` (
  `id` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL DEFAULT '',
  `url` text CHARACTER SET latin1 COLLATE latin1_general_cs,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `createddate` timestamp NULL DEFAULT NULL,
  `text` tinyint(4) NOT NULL DEFAULT '0',
  `visited` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;";

   if(!mysql_query($query))
   {
      $errmsg = "<font color=#CC3300>Error creating database: </font> ";	
      return false;
   }

   $query="INSERT INTO `$tablename` (`id`, `url`, `date`, `text`, `visited`) VALUES
('0', 'http://http://code.google.com/p/ksqurl/', NOW(), NOW(), 0);";

   if(!mysql_query($query))
   {
      $errmsg = "<font color=#CC3300>Error creating database: </font> ";
      return false;
   }


   return $result;
}
// End database functions
if(mysql_install_db($sql_database, $sql_table, $errmsg)) 
{ 
   echo "<font color=#00CA13>Success: </font>"; 
   echo "<font color=#00CA13>ksqUrl database successfully setup!</font><br />";
} else {
  die("".$errmsg."<br/>".mysql_error()); 
}  
mysql_close(); 

// write config file
echo "<h3>Writing config file</h3>";
if (file_exists($configfile)) {
    die("<font color=#CC3300>Error: $configfile already exist!</font>");
} else {
$fh = fopen($configfile, 'w') or die("<font color=#CC3300>Error: Cannot open file.</font>");
$configData = '<?php

/* ksqUrl / includes / config.php */
/* configuration and settings */
/* written by installer */


// mysql connection info
define(\'MYSQL_USER\', \''.$sql_username.'\');
define(\'MYSQL_PASS\', \''.$sql_password.'\');
define(\'MYSQL_DB\', \''.$sql_database.'\');
define(\'MYSQL_HOST\', \''.$sql_host.'\');

// table
define(\'URL_TABLE\', \''.$sql_table.'\');

// install path
define(\'INSTALL_PATH\', \''.$domain.'\');

// website name
define(\'APP_NAME\', \''.$webname.'\');

// true = use mod rewrite
// default = true
define(\'REWRITE\', true);

define(\'ALLOWED_CHARS\', \'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\');

// Do you want the searchpage enabled?  0=Disabled 1=Enabled
define(\'SEARCH_PAGE\', \''.$search_page.'\');

// Do you want to show random short URLs on the main page? 0=Disabled 1=Enabled
define (\'RANDOM_DISPLAY\', \''.$random_links.'\');


// allowed url prefixes
 $allowed_protocols = array(\'http:\', \'https:\', \'mailto:\');

// uncomment to skip the protocol check
// $allowed_procotols = array();

// feature control
// All features enabled by default

// Play .mp3\'s using flash player
define(\'MPLAY\', '.$play_mp3.');

// Play .flv\'s in flash player
define(\'VPLAY\', '.$play_flv.');

// Load images instead of forwarding
define(\'LIMAGE\', '.$play_img.');


// PhishTank.com App key
define(\'PTKEY\', \''.$appkey.'\');

// Dissallowed custom names
$badcustom = array(\'$$$\',
\'~\', 
\'free\', 
\'save\', 
\'hormone\', 
\'ababa\', 
\'alprazolam\', 
\'ariset\', 
\'blackjack\', 
\'buspar\', 
\'butalbital\', 
\'carisoprodol\', 
\'casino\', 
\'celexa\',
\'cialis\',
\'citibank\',
\'cyberturf\',
\'didrex\',
\'dosage\',
\'dx1\',
\'ejaculation\',
\'ejactulation\',
\'fioricet\',
\'foreclosure\',
\'forex\',
\'freemegavideo\',
\'gambling\',
\'hochulexus\',
\'holdem\',
\'hollyvalance\',
\'homeloan\',
\'horny\',
\'insurance\',
\'keno\',
\'mortgage\',
\'nasonex\',
\'nfsautoloan\',
\'penis\',
\'phentermine\',
\'poker\',
\'porevo\',
\'prequalify\',
\'prozac\',
\'refinance\',
\'ringtone\',
\'ringtones\',
\'slots\',
\'sperm\',
\'straponclub\',
\'tramadol\',
\'ultram\',
\'viagra\',
\'xanax\',
\'yasamohuel\',
\'yigan999\',
\'zyban\');

?>';
fwrite($fh, $configData);
fclose($fh);
echo "<font color=#00CA13>Success: </font><font color=#00CA13>$configfile was successfully created!</font><br/><br/>";

echo "<h2><font color=#00CA13>Installation Complete</font></h2><b>ksqUrl is now ready to run! Please delete the install folder now.</b>";

}
?>
</form>
